/**
 * 格式化活动日期显示
 * @param dateString 日期字符串
 * @returns 格式化后的日期显示文本
 */
export const formaAbbreviationDate = (dateString: string | Date): string => {
  const date = new Date(dateString);
  const now = new Date();
  const diffInHours = Math.floor(
    Math.abs(now.getTime() - date.getTime()) / (1000 * 60 * 60),
  );

  if (diffInHours < 24) {
    return `${diffInHours}h`;
  }

  const diffInDays = Math.floor(diffInHours / 24);
  if (diffInDays < 7) {
    return `${diffInDays}天`;
  }

  // 返回英文缩写月日格式，如 16 Jul
  const months = [
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sep',
    'Oct',
    'Nov',
    'Dec',
  ];
  return `${date.getDate()} ${months[date.getMonth()]}`;
};

// 格式化时间为 分钟:秒 (m:SS) 格式
export const formatTime = (minutes: number) => {
  const totalSeconds = Math.round(minutes * 60);
  const mins = Math.floor(totalSeconds / 60);
  const secs = totalSeconds % 60;
  return `${mins}:${secs.toString().padStart(2, '0')}`;
};

// 格式化剩余时间为小时和分钟
export const formatRemainingTime = (minutes: number) => {
  const hours = Math.floor(minutes / 60);
  const mins = Math.floor(minutes % 60);
  return { hours, mins };
};
